//
//  WYChannelModel.m
//  网易新闻19
//
//  Created by heima on 16/8/13.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "WYChannelModel.h"

@implementation WYChannelModel

+ (NSArray *)channels {
    // 1. 获取JSON的路径
    NSString *path = [[NSBundle mainBundle] pathForResource:@"topic_news.json" ofType:nil];
    
    // 2. 将其转成字典
    NSData *data = [NSData dataWithContentsOfFile:path];
    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL];
    
    // 3. 字典数组转模型数组
    NSArray *result = [NSArray yy_modelArrayWithClass:[self class] json:dict[@"tList"]];
    
    // 4. 作一个排序
    result = [result sortedArrayUsingComparator:^NSComparisonResult(WYChannelModel *obj1, WYChannelModel *obj2) {
        // 升序是 obj1 在前面, obj2 在后面
        return [obj1.tid compare:obj2.tid];
    }];
    return result;
}

- (NSString *)description {
    return [self yy_modelDescription];
}

@end
